<?php
/**
 * Created by PhpStorm.
 * User: fairy
 * Date: 14-3-6
 * Time: 上午11:12
 */

class PublicAction extends  BaseAction{
    public function login(){
        if(isset($_SESSION['email'])){
            redirect(U('/Admin'));
        }
        if (isset($_POST['email'])) {
            $email = trim(I('post.email'));
            $password = trim(I('post.password'));
            $map = array();
            $map['email'] = $email;
            $map['password'] = $password;
            $staff = M('Users')->where($map)->find();
//            $staff->query("SET NAMES utf8");
            echo '1';
            if (!empty($staff)) {
//                echo "登录正确";
                session_start();
                $_SESSION['email']=$email;
                redirect(U('/Admin'));
            } else {
                $this->error('登陆帐号信息不对请重新登陆！');
                echo '3';

            }
        }
    $this->display();

    }
    public function logout(){
        if(!isset($_SESSION['email'])){
            $this->error('您尚未登录！',U('/Index'));
        }
        else{
            $_SESSION=array();
            if(isset($_COOKIE[session_name()])){
                setcookie(session_name(),'',time()-1);
            }
            session_destroy();
            if(empty($_SESSION['email']))
            {
                $this->success("注销成功！",U('/Index'));
            }

        }
    }

} 